<script setup lang="ts">
import Versions from './components/Versions.vue'

// 调用接口
const uoload = async () =>{
  //调用接口，并或返回值
  var result = await window.electron.ipcRenderer.sendSync('uoload', "D:/test/test.txt")
  console.log(result)
}

//订阅后台信息,后台消息推送
var listenered = false;
const message = () => {
  if (!listenered) { //防止重复订阅
    //监听(订阅主题receive-message)来自主进程的消息
    window.electron.ipcRenderer.on('receive-message', (_event, message) => {
      console.log(message);
    });
    //向主进程发送推送消息
    window.electron.ipcRenderer.send('push-message', '000000000');
    listenered = true;
  }else{
    console.log("已经订阅过")
  }
  
}

</script>

<template>
  <img alt="logo" class="logo" src="./assets/electron.svg" />
  <div class="creator">Powered by electron-vite</div>
  <div class="text">
    Build an Electron app with
    <span class="vue">Vue</span>
    and
    <span class="ts">TypeScript</span>
  </div>
  <p class="tip">Please try pressing <code>F12</code> to open the devTool</p>
  <div class="actions">
    <div class="action">
      <a href="https://electron-vite.org/" target="_blank" rel="noreferrer">Documentation</a>
    </div>
    <div class="action">
      <a target="_blank" rel="noreferrer" @click="uoload">上传文件</a>
      <a target="_blank" rel="noreferrer" @click="message">订阅信息</a>
    </div>
  </div>
  <Versions />
</template>
